package com.janal.service.Postbar.bar;

import com.janal.model.Postbar.bar.PostBarDaoImpl;
import com.janal.model.Postbar.bar.Post_bar;
import com.janal.util.JdbcUtils;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Lenovo
 */
public class BarServiceImpl implements BarService{
    private PostBarDaoImpl pbdao;

    public BarServiceImpl(){
        pbdao = new PostBarDaoImpl();
    }

    @Override
    public boolean createBarService(Post_bar pb){
        Connection conn = null;
        boolean flag = false;
        try {
            conn = JdbcUtils.getConnection();
            if(pbdao.createPostBarDao(conn,pb)){
                flag = true;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.close(null,conn);
        }
        return flag;
    }

    @Override
    public List<Post_bar> getAllBarMessage() {
        Connection conn = null;
        List<Post_bar> pb = null;
        try {
            conn = JdbcUtils.getConnection();
            pb = pbdao.getAllBarMessageDao(conn,0);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.close(null,conn);
        }
        return pb;
    }
}
